/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.gac.gacmod.visual;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import org.netbeans.api.visual.action.ActionFactory;
import org.netbeans.api.visual.action.SelectProvider;
import org.netbeans.api.visual.action.TwoStateHoverProvider;
import org.netbeans.api.visual.action.WidgetAction;
import org.netbeans.api.visual.border.BorderFactory;
import org.netbeans.api.visual.widget.LabelWidget;
import org.netbeans.api.visual.widget.LabelWidget.Alignment;
import org.netbeans.api.visual.widget.Widget;

/**
 *
 * @author Tomek
 */
public class ButtonWidget extends Widget
{

    protected LabelWidget _label;
    protected boolean _expanded = true;
    protected IButtonClickListener _listener;

    public ButtonWidget(BoxScene scene, String label,
            IButtonClickListener listener)
    {
        super(scene);
        //this.setMinimumSize(new Dimension(10, 15));
        //this.setMaximumSize(new Dimension(100, 15));
        _listener = listener;

        _label = new LabelWidget(scene);
        _label.setAlignment(Alignment.CENTER);
        _label.setVerticalAlignment(LabelWidget.VerticalAlignment.BOTTOM);
        _label.setLabel(label);

        this.setBorder(BorderFactory.createRoundedBorder(3, 3, Color.WHITE,
                Color.LIGHT_GRAY));

        this.addChild(_label);

        this.getActions().addAction(ActionFactory.createSelectAction(
                new SelectProvider()
                {

                    public boolean isAimingAllowed(Widget arg0, Point arg1,
                            boolean arg2)
                    {
                        return true;
                    }

                    public boolean isSelectionAllowed(Widget arg0, Point arg1,
                            boolean arg2)
                    {
                        return true;
                    }

                    public void select(Widget arg0, Point arg1, boolean arg2)
                    {

                        if (_listener != null)
                        {
                            _listener.Click();
                        }
                    }
                }));
        WidgetAction a = ActionFactory.createHoverAction(new TwoStateHoverProvider()
        {

            public void unsetHovering(Widget arg0)
            {
                arg0.setBorder(BorderFactory.createRoundedBorder(3, 3,
                        Color.WHITE, Color.LIGHT_GRAY));
            }

            public void setHovering(Widget arg0)
            {
                arg0.setBorder(BorderFactory.createRoundedBorder(3, 3,
                        Color.WHITE, Color.BLACK));
            }
        });

        this.getActions().addAction(a);
        scene.getActions().addAction(a);
    }
}
